package com.solar.etl.config.mapping;

import java.util.Iterator;
import java.util.Vector;

import org.dom4j.Element;

import com.solar.etl.spi.ParserCfg;

public class FieldSet implements ParserCfg<FieldSet>{
	public Vector<Field> fields;
	public FieldSet(){
		this.fields=new Vector<Field>();
	}
	public void put(Field field){
		this.fields.add(field);
	}
	public Field getFieldByName(String destName){
		Field field=null;
		for (Field tem : fields) {
			if(destName.equals(tem.destName)){
				field=tem;break;
			}
		}
		return field;
	}
	
	@Override
	public FieldSet parser(Element e) {
		Iterator mapes =e.elementIterator();
		 while(mapes.hasNext()){
			 Element mape = (Element) mapes.next();
			 fields.add(new Field().parser(mape));
		 }
		return this;
	}
	public String toString(){
		StringBuffer sbr=new StringBuffer();
		for (int i = 0; i < fields.size(); i++) {
			Field field=fields.get(i);
			sbr.append(field.srcName).append(" : ").append(field.srcValue);
		}
		sbr.append("\n");
		return sbr.toString();
	}
}
